package br.com.ca5.dao.impl;

import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import org.springframework.stereotype.Repository;

import br.com.ca5.dao.DocumentoCategoriaDao;
import br.com.ca5.entity.DocumentoCategoria;

@Repository
public class DocumentoCategoriaDaoImpl extends HibernateDaoSupport implements
		DocumentoCategoriaDao {
	private static final Log log = LogFactory
			.getLog(DocumentoCategoriaDaoImpl.class);

	@SuppressWarnings("unchecked")
	public List findAll() {
		log.debug("finding all DocumentoCategoria instances");
		try {
			String queryString = "from DocumentoCategoria";
			return getHibernateTemplate().find(queryString);
		} catch (RuntimeException re) {
			log.error("find all failed", re);
			throw re;
		}
	}

	@SuppressWarnings("unchecked")
	public List<DocumentoCategoria> find(DocumentoCategoria categoriaCrud) {
		log.debug("finding DocumentoCategoria instance by example");
		try {
			List<DocumentoCategoria> results = getHibernateTemplate()
					.findByExample(categoriaCrud);
			log.debug("find by example successful, result size: "
					+ results.size());

			return results;
		} catch (RuntimeException re) {
			log.error("find by example failed", re);
			throw re;
		}
	}

	public void delete(DocumentoCategoria persistentInstance) {
		log.debug("deleting DocumentoCategoria instance");
		try {
			getHibernateTemplate().delete(persistentInstance);
			log.debug("delete successful");
		} catch (RuntimeException re) {
			log.error("delete failed", re);
			throw re;
		}

	}

	public void save(DocumentoCategoria transientInstance) {
		log.debug("saving DocumentoCategoria instance");
		try {
			getHibernateTemplate().saveOrUpdate(transientInstance);
			log.debug("save successful");
		} catch (RuntimeException re) {
			log.error("save failed", re);
			throw re;
		}

	}

	public DocumentoCategoria load(DocumentoCategoria documentoCategoria) {
		log.debug("finding DocumentoCategoria instance by example");
		try {
			DocumentoCategoria result = (DocumentoCategoria) getHibernateTemplate()
					.load(DocumentoCategoria.class, documentoCategoria.getId());
			log.debug("load success" + result.getId());

			return result;
		} catch (RuntimeException re) {
			log.error("load failed", re);
			throw re;
		}
	}

}
